package com.job.tencent;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName: test.Tencent2
 * @Description:
 * @Author: 12071
 * @Date: 2022/4/24 20:25
 */
public class Tencent2 {
    static int[] tmp = getPrime(200000);

    public static void main(String[] args) {
        System.out.println(Arrays.toString(getPrime(10)));
    }

    public static int getNumber (int[] a) {
        // write code here
        List<Integer> list = new ArrayList<>();
        for (int item : a) {
            list.add(item);
        }
        while (list.size()>1){
            List<Integer> list2 = new ArrayList<>();
            for (int i : tmp) {
                if(i<=list.size()){
                    list2.add(list.get(i-1));
                }else{
                    break;
                }
            }
            list = list2;
        }
        return list.get(0);
    }

    public static int[] getPrime(int n){
        boolean[] valid = new boolean[n+1];
        int[] prime = new int[n+1];
        int tot = 0;
        for (int i = 2; i <=n; i++) {
            if(!valid[i])
                prime[tot++] =i;
            for (int j = 0; ((j<tot) && ((long)i*prime[j] <= n)); j++) {
                valid[i*prime[j]] = true;
                if(i%prime[j] == 0)
                    break;
            }
        }
        return Arrays.copyOf(prime, tot);
    }
}
